package com.isoftstone.service.impl;

import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import com.isoftstone.dao.UsersDAO;
import com.isoftstone.pojo.Users;
import com.isoftstone.service.UsersService;

@Service
public class UsersServiceImpl implements UsersService{
	@Autowired
	private UsersDAO usersDAO;

	@Override
	public int register(Users users) {
		System.out.println("录入成功！");
		return usersDAO.insert(users);
	}

	@Override
	public int dismiss(int id) {
		System.out.println(id);
		System.out.println("删除成功！");
		return usersDAO.delete(id);
	}

	@Override
	public int update(Users users) {
		System.out.println("修改成功！");
		return usersDAO.update(users);
	}

	@Override
	public List<Users> getAllUsers() {
		List<Users> list=usersDAO.selectAll();
		System.out.println("查询成功！");
		if(list!=null)
			System.out.println("查到了东西");
		else {
			System.out.println("空空如也");
		}
		return list;
	}
	
	@Override
	public int check(String username,String password) {
		int i = usersDAO.getIdByLogin(username,password);
		if(i>0)
		{
			System.out.println("验证成功！");
			return 1;
		}
		else {
			return 0;
		}
	}

	@Override
	public Users getUsersById(int id) {
		Users list=usersDAO.selectById(id);
		System.out.println(id);
		if(list!=null)
		{
			System.out.println("定位成功");
		}
		else {
			System.out.println("定位失败");
		}
		return list;
	}

	@Override
	public Users getUsersByName(String username) {
		Users users = usersDAO.getUsersByName(username);
		return users;
	}

}
